
package com.netease.xone.widget.tabview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.netease.xone.R;

public class ProfileTab extends AbsTabView {

    private boolean mIsSelf;
    private TextView[] mCountTexts;

    /**
     * @param context
     * @param isSelf 标识是我的主页还是他人主页
     */
    public ProfileTab(Context context, boolean isSelf) {
        this(context, null);
        mIsSelf = isSelf;
    }

    public ProfileTab(Context context, AttributeSet attrs) {
        super(context, attrs, false);//不自动创建
        mCountTexts = new TextView[getTabCount()];
    }

    @Override
    public int getTabCount() {
        return 5;
    }

    @Override
    public int getTabDividerStyle() {
        return DIVIDER_NONE;
    }

    @Override
    public int getTabDividerResource() {
        return 0;
    }

    @Override
    public View getTabView(int index) {
        LinearLayout tab = (LinearLayout)View.inflate(mContext, R.layout.view_profile_tab_item,
                null);
        tab.setClickable(true);
        TextView tv = (TextView)tab.findViewById(R.id.profile_tab_name);
        mCountTexts[index] = (TextView)tab.findViewById(R.id.profile_tab_count);
        if (index == 0) {
            tv.setText(R.string.profile_tab_my_discuss);
        } else if (index == 1) {
            tv.setText(R.string.profile_tab_subscribe);
        } else if (index == 2) {
            tv.setText(R.string.profile_tab_praise);
        } else if (index == 3) {
            if (mIsSelf) {
                tv.setText(R.string.profile_tab_comment);
            } else {

            }
        } else if (index == 4) {
            if (mIsSelf) {
                tv.setText(R.string.profile_tab_draft);
            } else {

            }
        }
        return tab;
    }

    public void setCountText(int index, int count) {
        if (index >= 0 && index < getTabCount()) {
            mCountTexts[index].setText(String.valueOf(count));
        }
    }


    public int getCount(int index){
        int count = 0;
        if (index >= 0 && index < getTabCount()) {
            count = Integer.valueOf(mCountTexts[index].getText().toString());
        }
        return count;
    }

}
